<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>质数判断</title>
</head>
<body>
<script>
  function isPrime(num) {

    for (let i = 2; i < num; i++) {
      if (num % i === 0) {
        return false
      }
    }
    return true
  }

  function isPrime2(num) {
    let tmp = Math.ceil(Math.sqrt(num))

    for (let i = 2; i < tmp; i++) {
      if (num % i === 0) {
        return false
      }
    }
    return true
  }

  alert(isPrime2(15))

</script>
</body>
</html>